import Stream from "node:stream";

function ReadStream(stream) {
  if (stream instanceof Stream) {
    return new Promise((resolve, reject) => {
      let body = "";
      stream.on("data", (data) => {
        body += data;
      });
      stream.on("end", () => {
        resolve(body);
      });
      stream.on("error", (error) => {
        reject(error);
      });
    });
  }
  return stream;
}

export default ReadStream;
